#pragma once

#include "wlroots.hpp"
#include "view.h"
#include "view_interface.h"

#include <sigc++/sigc++.h>

class Server;

// class XdgView : public View, public ViewInterface
class XdgView : public ViewInterface
{
public:
    XdgView(struct wlr_xdg_surface* xdg_surface, Server* server);

    inline View* view() { return m_base; }

    void set_output(OutputWrapper *output);
    inline OutputWrapper* output() { return m_base->output(); }

    sigc::signal<void(XdgView*)> sig_toplevel_request_move;
    sigc::signal<void(XdgView*, wlr_edges)> sig_toplevel_request_resize; // toplevel, edges
    sigc::signal<void(XdgView*)> sig_toplevel_request_maximize;

protected:
    virtual void configure(wlr_box geo) override;
    virtual void close() override;
    virtual const char *get_string_prop(const char *prop) override;
    virtual void map() override;
    virtual void set_activated(struct wlr_surface *surface, bool activated) override;
    virtual void set_fullscreen(bool fullscreen) override;
    virtual void notify_tiled() override;
    virtual void unmap(bool client_request) override;
    virtual void maximize(bool maximize) override;
    virtual void minimize(bool minimize) override;
    virtual void move_to_front() override;
    virtual void move_to_back() override;
    virtual View *get_root() override;
    virtual void append_children(wl_array *children) override;
    virtual bool is_related(wlr_surface *surface) override;
    virtual view_size_hints get_size_hints() override;
    virtual view_wants_focus wants_focus() override;
    virtual bool has_strut_partial() override;
    virtual wlr_surface *surface_at(double vx, double vy, double *sx, double *sy) override;
    virtual wlr_box get_surface_geometry() override;
    virtual void resize(wlr_box geo) override;
    virtual void focus() override;
    virtual bool is_toplevel() override;

private:
    void init_foreign_toplevel();
    void commit();
    struct wlr_xdg_toplevel *top_parent_of_view();

    void destroy();
    void request_move();
    void request_resize(struct wlr_xdg_toplevel_resize_event *event);
    void request_maximize();
    void request_minimize();
    void request_fullscreen();
    void set_title();
    void set_app_id();
    void new_popup();

private:
    View* m_base;
    // Server* m_server;

    struct wlr_xdg_surface *m_xdg_surface;

    /* Events unique to xdg-toplevel views */
    wl_listener_wrapper m_set_app_id;
    wl_listener_wrapper m_new_popup;
};
